package cn.com.uthink.filter;

import java.io.File;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.ServletContextAware;

import cn.com.uthink.util.ConfigUtil;

/**
 * @description: 初始化
 */
public class InitializationListener implements ServletContextAware, ApplicationListener<ContextRefreshedEvent> {

	private ServletContext servletContext;
	@Autowired
	private ConfigUtil configUtil;

	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

	@Override
	public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
		if (servletContext != null && contextRefreshedEvent.getApplicationContext().getParent() == null) {
			try {
				File file = new File(configUtil.getDownloadAbsoluteFilePath());
				if (!file.exists()) {
					file.mkdirs();
				}
			} catch (Exception e) {
			}
		}
	}
}